//
//  ZYCTeachingAttendanceDetailViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/29.
//

#import "ZYCTeachingAttendanceDetailViewController.h"
#import "XLPageViewController.h"
#import "XLPageViewControllerConfig.h"
#import "ZYCTeachingAttendanceCourseDetaiViewController.h"
#import "ZYCTeachingAttendanceCourseEvaluationViewController.h"
#import "ZYCAttendanceCourseEvaluationDetailViewController.h"
#import "ZYCTeachingAttendanceEvaluateViewController.h"
#import "BTImageTitleButton.h"
@interface ZYCTeachingAttendanceDetailViewController ()<XLPageViewControllerDataSrouce,XLPageViewControllerDelegate>
@property (nonatomic, strong) XLPageViewControllerConfig * config;
@property (nonatomic, strong) XLPageViewController* pageViewController;
@property (nonatomic, strong) NSArray *titles;


@property (nonatomic, strong) BTImageTitleButton *rightButton;


@end

@implementation ZYCTeachingAttendanceDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"详情";

    [self.view addSubview:self.pageViewController.view];
    
    if ([self.overFlag isEqualToString:@"doing"]) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
    }
}


#pragma make - XLPageViewControllerDelegate
-(NSInteger) pageViewControllerNumberOfPage{
    return self.titles.count;
}

-(UIViewController *) pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index{
    if (index == 0) {
        ZYCTeachingAttendanceCourseDetaiViewController * vc = [[ZYCTeachingAttendanceCourseDetaiViewController alloc] init];
        vc.listenClassId = self.listenClassId;
        return vc;
    }else if (index == 1) {
        ZYCTeachingAttendanceCourseEvaluationViewController * vc = [[ZYCTeachingAttendanceCourseEvaluationViewController alloc] init];
        vc.listenClassId = self.listenClassId;
        return vc;
    }
    return nil;
}

-(NSString *) pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index
{
    return self.titles[index];
}


- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index{
    
}
- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@"课程详情",@"课程评价"];
    }
    return _titles;
}

-(XLPageViewController *) pageViewController
{
    if (!_pageViewController) {
        _pageViewController = [[XLPageViewController alloc] initWithConfig:self.config];
        _pageViewController.view.frame = CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight);
        _pageViewController.delegate = self;
        _pageViewController.dataSource = self;
        _pageViewController.scrollEnabled = NO;
        [self addChildViewController:self.pageViewController];
    }
    return _pageViewController;
}

-(XLPageViewControllerConfig *) config{
    if (!_config) {
        _config = [XLPageViewControllerConfig defaultConfig];
        _config.titleViewAlignment = 100.f;
        _config.titleSpace = 0;
        _config.titleWidth = kScreenWidth / 2;
        _config.titleViewHeight = 46.0f;
//        _config.titleViewInset = UIEdgeInsetsMake(0, 20, 0, 20);
        _config.titleSelectedColor = HEX_RGB(kTitleMainColor);
        _config.titleSelectedFont = kCustomFont(@"PingFangSC-Regular", 15.0f);
        _config.titleNormalFont = kCustomFont(@"PingFangSC-Regular", 15.0f);
        _config.titleNormalColor = HEX_RGB(kTitleLightGrayColor);
        _config.shadowLineHidden = NO;
        _config.shadowLineHeight = 4.0f;
        _config.shadowLineWidth = 15.0f;
        _config.shadowLineCap = XLPageShadowLineCapRound;
        _config.separatorLineHidden = YES;
        _config.titleColorTransition = false;
        _config.shadowLineColor = HEX_RGB(kTitleMainColor);
    }
    return _config;
}

- (void)clickRightItem:(UIButton *)sender{
    [self judgeEvalFag];
//    ZYCTeachingAttendanceEvaluateViewController *vc = [ZYCTeachingAttendanceEvaluateViewController new];
//    [self.navigationController pushViewController:vc animated:YES];
}

- (BTImageTitleButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [[BTImageTitleButton alloc] init];
        [_rightButton setTitle:@"去评课" forState:UIControlStateNormal];
        [_rightButton setImage:[UIImage imageNamed:@"dianzan"] forState:UIControlStateNormal];
        [_rightButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        _rightButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);
        [_rightButton addTarget:self action:@selector(clickRightItem:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightButton;
}

- (void)judgeEvalFag{
    NSDictionary *params = @{
        @"listenClassId":self.listenClassId
    };
    [[URLManager sharedURLManager] postUrlString:Appliance_Post_TeachAttendanccGetEvalFlag requestService:RequestServiceWorkBench parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            if (SUCCESS(responseObject[@"code"])) {
                if ([responseObject[@"body"] boolValue] == YES) {
                    ZYCAttendanceCourseEvaluationDetailViewController *vc = [ZYCAttendanceCourseEvaluationDetailViewController new];
                    vc.listenClassId = self.listenClassId;
                    [self.navigationController pushViewController:vc animated:YES];
                }else{
                    ZYCTeachingAttendanceEvaluateViewController *vc = [ZYCTeachingAttendanceEvaluateViewController new];
                    vc.listenClassId = self.listenClassId;
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
